package com.hy.study.mapper;

import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author huyong
 * @date 2024 年 02 月 07 日 16:22: 18
 */
public class OneShareFriendsMapper extends Mapper<LongWritable, Text, Text, Text> {

    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, Text>.Context context) throws IOException, InterruptedException {
        String line = value.toString();
        if (StringUtils.isBlank(line)) {
            return;
        }

        String[] split = line.split(":");
        if (split.length < 2) {
            return;
        }
        String friend = split[0];
        String[] names = split[1].split(",");
        for (String name : names) {
            context.write(new Text(name), new Text(friend));
        }
    }
}
